package com.rede.didiok.user.modulelist.community.manager;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rede.didiok.common.enums.ResourceTypeEnum;
import com.rede.didiok.common.exception.exceptionType.InsertException;
import com.rede.didiok.user.modulelist.community.dao.MomentCommentDao;
import com.rede.didiok.user.modulelist.community.dao.UserMomentDao;
import com.rede.didiok.user.modulelist.community.entity.MomentCommentEntity;
import com.rede.didiok.user.modulelist.community.entity.UserMomentEntity;

/**
 * @Author: Rede
 * @DateTime: 2024-01-13 9:14
 * @Description: 公共方法
 */
@Service("communityCommonManager")
public class CommunityCommonManager {

    @Resource
    private MomentCommentDao momentCommentDao;
    @Resource
    private UserMomentDao userMomentDao;


    /**
     * 通过资源类型获取用户uid
     *
     * @param resourceType
     * @param resourceUid
     * @return
     */
    public String getUserUidByResource(ResourceTypeEnum resourceType, String resourceUid) {
        String userUid = "";
        switch (resourceType) {
            case MOMENT: {
                UserMomentEntity userMoment = userMomentDao.selectById(resourceUid);
                if (userMoment != null) {
                    userUid = userMoment.getCreateUserUid();
                }
            }
            break;
            case MOMENT_COMMENT: {
                MomentCommentEntity comment = momentCommentDao.selectById(resourceUid);
                if (comment != null) {
                    userUid = comment.getCreateUserUid();
                }
            }
            break;
            default:
                throw new InsertException("类型转换异常: resourceType:" + resourceType);
        }
        return userUid;
    }
}
